<?php

flep_session_start();

function flep_request_popup($flep_page_info) {

  if (file_exists(_FLEP_PAGE_DIR_. basename($flep_page_info['page']) . ".inc.php")) {
    include _FLEP_PAGE_DIR_. basename($flep_page_info['page']) . ".inc.php";
  } else {
    header("HTTP/1.1 500 Internal Server Error", true, 500);
    printf("<b>Page Not Found.</b>");
    exit();
  }
  printf("<div id='header_files'>");
  flep_html_print_css($flep_page_info);
  flep_html_print_js($flep_page_info);
  printf("</div>");
}

if (isset($_GET["page"])) {
  if (!flep_valid_login($_SESSION['user'])) {
    header("HTTP/1.1 403 Forbidden", true, 500);
    printf("Please start a new session.");
    exit();
  }
  flep_request_popup($_GET);
  exit();
}

if(isset($_GET['res'])){
  if (file_exists(_FLEP_IMG_DIR_. basename($_GET['res']))) {
    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    header('Content-type: '.finfo_file($finfo, _FLEP_IMG_DIR_. basename($_GET['res'])));
    finfo_close($finfo);
    include _FLEP_IMG_DIR_. basename($_GET['res']);
  } else
  if (file_exists(_FLEP_CSS_DIR_. basename($_GET['res']))) {
    header('Content-type: text/css');
    include _FLEP_CSS_DIR_. basename($_GET['res']);
  } else
  if (file_exists(_FLEP_JS_DIR_. basename($_GET['res']))) {
    header('Content-type: text/javascript');
    include _FLEP_JS_DIR_. basename($_GET['res']);
  } else {
    header("HTTP/1.1 404 Forbidden", true, 404);
  }
  exit();
}
?>
